<?php
include("funciones/setup.php");
conecta();

session_start();
if(isset($_SESSION['sesion_usuario']))
{
	$id=$_GET['id'];
	
	if(isset($id))
	{
		$sql="select * from pagos where id_pago=".$id;
		$reg=mysql_query($sql);
		$datos=mysql_fetch_array($reg);
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Modulo de Pagos</title>
<link href="css/estilos_forms.css" rel="stylesheet" type="text/css" />
<link href="css/kendo.common.css" rel="stylesheet"/>
<link href="css/kendo.default.css" rel="stylesheet"/>
<link rel="stylesheet" type="text/css" href="css/paginador_busqueda.css"/>

<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.custom.css">
<link rel="stylesheet" type="text/css" href="css/autocomplete.css"/>
<link rel="stylesheet" type="text/css" media="screen"  href="css/calendario.css"> 
<link rel="stylesheet" type="text/css" media="screen" href="css/datePicker.css">
<link rel="stylesheet" type="text/css" href="js/fancybox/jquery.fancybox-1.3.4.css"/>

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>

<script src="js/pagos.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.core.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.numerictextbox.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.validator.js" language="javascript" type="text/javascript"></script>
<script src="js/kendo.combobox.js" language="javascript" type="text/javascript"></script>

<script src="js/fancybox/jquery.fancybox-1.3.4.pack.js" language="javascript" type="text/javascript"></script>
<script src="js/fancybox/jquery.mousewheel-3.0.4.pack.js" language="javascript" type="text/javascript"></script>

<script type="text/javascript" src="jquery-1.2.1.pack.js"></script>
<script src="js/date.js" type="text/javascript"></script>
<script src="js/jquery.datePicker.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function lookup(inputString) {
		if(inputString.length == 0) {
			$('#suggestions').hide();
		} else {
			$.post("busqueda_factura.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup
	
	function fill(thisValue,thisValue2) {
		$('#frm_factura').val(thisValue);
		$('#id_factura').val(thisValue2);
		setTimeout("$('#suggestions').hide();", 200);
	}
	
	function lookup2(inputString) {
		if(inputString.length == 0) {
			$('#suggestions2').hide();
		} else {
			$.post("busqueda_vendedor.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions2').show();
					$('#autoSuggestionsList2').html(data);
				}
			});
		}
	} // lookup
	
	function fill2(thisValue,thisValue2) {
		$('#frm_vendedor').val(thisValue2);
		$("#id_vendedor").val(thisValue);
		setTimeout("$('#suggestions2').hide();", 200);
	}		
</script>
<style type="text/css">
	.suggestionsBox {
		position: relative;
		left: 30px;
		margin: 10px 0px 0px 0px;
		width: 200px;
		background-color: #212427;
		-moz-border-radius: 7px;
		-webkit-border-radius: 7px;
		border: 2px solid #000;	
		color: #fff;
	}
	
	.suggestionList {
		margin: 0px;
		padding: 0px;
	}
	
	.suggestionList li {
		
		margin: 0px 0px 3px 0px;
		list-style-type:none;
		padding: 3px;
		cursor: pointer;
	}
	
	.suggestionList li:hover {
		background-color: #659CD8;
	}
</style>
<link href="css/estilos_base.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td><div id="credenciales">
      <table width="100%" border="0" cellspacing="3" cellpadding="0">
        <tr>
          <td width="42"><img src="imagenes/iconos/credenciales.png" width="42" height="28" /></td>
          <td class="fuente_normal">Bienvenido : <?php echo $_SESSION['sesion_usuario'];?></td>
        </tr>
        <tr>
          <td colspan="2"><table border="0" align="center" cellpadding="0" cellspacing="3">
            <tr>
              <td><a href="cerrar_sesion.php"><img src="imagenes/iconos/salir_session.png" width="22" height="23" border="0" /></a></td>
              <td class="fuente_normal"><a href="cerrar_sesion.php">Cerrar Sessión</a></td>
              <td class="fuente_normal">|</td>
              <td class="fuente_normal"><a href="panel_principal.php"><img src="imagenes/iconos/ico_panel_principal.png" width="22" height="23" border="0" /></a></td>
              <td class="fuente_normal"><a href="panel_principal.php">Panel Principal</a></td>
            </tr>
          </table></td>
        </tr>
      </table>
    </div></td>
    <td><div id="logotipo"><img src="imagenes/logo.png" width="200" height="82" /></div></td>
    <td><table border="0" align="right" cellpadding="0" cellspacing="5">
      <tr>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td><span class="fuente_login">La Serena, <?php echo fecha_hoy_mas_dia();?>&nbsp;</span></td>
      </tr>
    </table></td>
  </tr>
</table>
<br />
<div id="modulo">
  <form id="form1" name="form1" method="post" action="">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="5">
      <tr>
        <td class="fuente_formularios">Fecha Pago :</td>
        <td class="fuente_formularios"><input name="frm_fecha" type="text" class="k-textbox date-pick" id="frm_fecha" value="<?php if(isset($id)) { echo fecha_formato_espanol_gore($datos['fecha_pago']);  } ?>" size="12"   required="required"/></td>
        <td class="fuente_formularios">&nbsp;</td>
        <td width="5" colspan="2" class="fuente_formularios">&nbsp;</td>
      </tr>
     
      
      <tr>
        <td class="fuente_formularios">Factura:</td>
        <td class="fuente_formularios">
        <input name="frm_factura" type="text" class="k-textbox" id="frm_factura" onblur="fill();" onkeyup="lookup(this.value);" value="<?php echo $datos['id_factura']?>" size="30" placeholder="Buscar Factura" required<?php if(isset($id)){ ?> disabled="disabled" <?php } ?>/> 
        <div class="suggestionsBox" id="suggestions" style="display: none;">
			  <img src="imagenes/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
    <div class="suggestionList" id="autoSuggestionsList"></div></div>
    </td>
        <td class="fuente_formularios">Vendedor :</td>
        <td class="fuente_formularios">
        <?php 
		if(isset($id)){
			$q_ven="select * from vendedor where id_ven=".$datos['id_ven'];
			$r_ven=mysql_query($q_ven);
			$r_vender=mysql_fetch_array($r_ven);
		}
		?>
        <input type="text" name="frm_vendedor" id="frm_vendedor" class="k-textbox" size="35" onkeyup="lookup2(this.value);" onblur="fill2();" placeholder="Buscar Vendedor" value="<?php echo $r_vender['nombre_ven']?>" required <?php if(isset($id)){ ?> disabled="disabled" <?php } ?>/> 
        <div class="suggestionsBox" id="suggestions2" style="display: none;">
			  <img src="imagenes/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
    <div class="suggestionList" id="autoSuggestionsList2"></div></div></td>
      </tr>
      <tr>
        <td class="fuente_formularios">Tipo de Pago :</td>
        <td class="fuente_formularios"><div class="suggestionsBox" id="suggestions" style="display: none;">
			  <img src="imagenes/upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
    <div class="suggestionList" id="autoSuggestionsList">
					&nbsp;
				</div>
           </div>
          <label for="frm_pago">
            <select name="frm_pago" id="frm_pago">
              <option value="0">Seleccione Medio de Pago</option>
              <option value="1"<?php if($datos['tipo_pago']==1){?> selected="selected"<?php } ?>>Cheque</option>
              <option value="2"<?php if($datos['tipo_pago']==2){?>selected="selected"<?php } ?>>Efectivo</option>
              <option value="3"<?php if($datos['tipo_pago']==3){?>selected="selected"<?php } ?>>Transferencias</option>
            </select>
          </label></td>
        <td colspan="2" class="fuente_formularios">
        <?php if(isset($id)){ ?><a href="#" onclick="detalle_factura();"> <img src="imagenes/iconos/ico_ver_doc.png" width="16" height="16" border="0" />&nbsp;Ver Detalle Factura</a><?php } ?>
         <?php if(isset($id)){ 
		 	$sql_fac="SELECT * FROM factura_guia where id_factura=".$datos['id_factura'];
			$r_fac=mysql_query($sql_fac);
			$fila_fac=mysql_fetch_array($r_fac);
		 ?>
         	<a href="#" onclick="detalle_guia(<?php echo $fila_fac['id_guia']; ?>);"> </a><a href="#" onclick="detalle_factura();"><img src="imagenes/iconos/ico_ver_doc.png" width="16" height="16" border="0" /></a>&nbsp;<a href="#" onclick="detalle_guia(<?php echo $fila_fac['id_guia']; ?>);">Ver Detalle Guia</a>
		 <?php } ?>
<input name="id_factura" type="hidden" id="id_factura"  />
            <input type="hidden" name="id_vendedor" id="id_vendedor" />
       </td>
      </tr>
      <?php if(isset($id)){ ?>
      <tr>
        <td colspan="5" class="fuente_formularios"><div id="mst_cheques"></div></td>
      </tr>
		<?php } ?>
        <tr>
        <td class="fuente_formularios">Nº Documento :</td>
        <td class="fuente_formularios"><label for="frm_documento"></label>
        <input class="k-textbox" name="frm_documento" type="text" id="frm_documento"placeholder="Ingra el Nº de Documento" required value="<?php echo $datos['n_documento']; ?>" /></td>
        <td class="fuente_formularios">Nº Cuenta :</td>
        <td class="fuente_formularios"><input class="k-textbox" name="frm_cuenta" type="text" id="frm_cuenta" placeholder="Ingresa el Nº de Cuenta" required value="<?php echo $datos['n_cuenta']; ?>" /></td>
      </tr>
      <?php if(isset($id)){ ?>
      <tr>
	      <td class="fuente_formularios">&nbsp;</td>
      	<td class="fuente_formularios">&nbsp;</td>
        <td class="fuente_formularios">Total Factura :</td>
        <td class="fuente_formularios">
		<?php
				$sql_fac="select * from factura where id_factura=".$datos['id_factura'];
				$r_fac=mysql_query($sql_fac);
				$filas_factura=mysql_fetch_array($r_fac);
				;
		 ?>
		<input name="frm_total" type="text" id="frm_total" class="k-textbox fuente_texto_factura"  size="15" value="<?php echo $filas_factura['total']; ?>" disabled="disabled"  /></td>
      </tr>
      <?php if($datos['tipo_pago']==1){ ?>
       <tr>
	      <td class="fuente_formularios">&nbsp;</td>
      	<td colspan="2" align="right" class="fuente_formularios">Diferencia Pago - Total Factura:</td>
        <td class="fuente_formularios">
        <input name="frm_diferencia_pago" type="text" id="frm_diferencia_pago" class="k-textbox fuente_texto_dif_pagos"  size="15" value="" disabled="disabled"  /></td>
      </tr>
      <?php 
	   }
	  } ?>
      <tr>
        <td colspan="5"><div id="proveedores"></div></td>
      </tr>
      <tr>
        <td colspan="5"><center>
          <label for="oculto_id"></label>
          <input type="hidden" name="id_oculto" id="id_oculto" value="<?php echo $id;?>" />
          <?php
		    if(!isset($id))
			{
				?>
            <input type="button" name="btn_ingresar" id="btn_ingresar" value="Ingresar" class="k-button"/> 
            &nbsp;
            <?php
			}
			else
			{?>
            <input type="button" name="btn_modificar" id="btn_modificar" value="Modificar" class="k-button"/>
            &nbsp;
			<input type="button" name="btn_eliminar" id="btn_eliminar" value="Eliminar" class="k-button"/>
			&nbsp;
            <?php
			}
			?>
<input type="button" name="btn_ingresar4" id="btn_cancelar" value="Cancelar" class="k-button"/>
        </center></td>
      </tr>
    </table>
  </form>
</div>
<br />
<div id="paginador"></div>
<script language="javascript">
$(document).ready(function(){
	$("#proveedores").hide();
$("#btn_ingresar").click(function(){
	/*if($("#frm_documento").val()==""){
		alert("Debe ingresar el numero del documento");
		$("#frm_documento").focus();
	} else {
		if($("#frm_cuenta").val()==""){
			alert("Debe ingresar el numero de cuenta");
			$("#frm_cuenta").focus();
			} else {*/
					if($("#frm_factura").val()=="" && $("#id_factura").val()==""){
						alert("Debe Buscar e ingresar el numero de factura");
						$("#frm_factura").focus();
						} else {
							if($("#frm_vendedor").val()=="" && $("#id_vendedor").val()==""){
								alert("Debe Buscar e ingresar al vendedor");
								$("#frm_factura").focus();
								} else {
										if($("#frm_pago").val()==0){
											alert("Debe Seleccionar El medio de pago");
										} else {
											ingresar();			
										}
								}
						}
						/*
		}
	}*/
	});
	
	$("#btn_modificar").click(function(){
		modificar();
	});
	
	$("#btn_eliminar").click(function(){
		elimina();
	});
	
	$("#btn_cancelar").click(function(){
		location.href="pagos.php";
	});
	
	

	$("#paginador").html(muestra_grilla());
	
	$("#proveedores").html(muestra_grilla_che(<?php echo $id; ?>));
	
  	<?php  if(isset($id)){ ?>
	$("#mst_cheques").html();
	$("#proveedores").show();
	<?php } ?>
	$('.date-pick').datePicker({
	 startDate:'01/01/2000',
    clickInput:true
   }).val(<? if(!isset($id)){ ?>new Date().asString()<? }?>);
	$("#frm_pago").change(function(){if(($("#frm_pago").val()==1) || ($("#frm_pago").val()==2)){ frm_cheques(); } else {$("#mst_cheques").html(' ');}	});
	<?php if($datos['tipo_pago']==1){ ?> frm_cheques();  <?php } ?>
});

</script>
</body>
</html>
<?php
}
else
{
	header("Location:index.php");
}
?>